<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class pengeluaran extends CI_Controller {
	
	function __construct(){		
		parent::__construct();	
		//$this->load->library('Excel_generator');
		//$this->output->enable_profiler(true);
		
		$this->load->model('mdl_pemasukan');
	}
	
	function index(){
		$data['page_title']='Daftar pengeluaran Desa';
		$data['page_icon']='icon-money';
		$data['page_content']='pengeluaran';
		$this->load->view('layout/master',$data);
	}
	
	
	function grid(){
		$data = $this->mdl_pemasukan->getdataP();
		echo $this->mdl_pemasukan->togrid($data['row_data'], $data['row_count']);
	}
	
	function add(){
		
		$data['id'] = '';
		$data['kode'] = '';
		$data['urusan'] = '';
		$data['tanggal'] = date('d/m/Y');
		$data['jumlah'] = '';
		$data['pengurus'] = '';
		$data['uraian'] = '';

		$this->load->view('pengeluaran_form', $data);
	}
	
	function save(){
		# init
		$status = "";
		$result = false;
		$data['pesan_error'] = '';
		
		# get post data
		foreach($_POST as $key => $value){
			$data[$key] = $value;
		}
		
		# rules validasi form
		$this->form_validation->set_rules("kode", 'Kode Rekening', 'trim|required|xss_clean');
		//$this->form_validation->set_rules("urusan", 'Urusan', 'trim|required|xss_clean');
		# message rules
		$this->form_validation->set_message('required', 'Field %s harus diisi.');

		$data['pesan_error'] = '';
		if ($this->form_validation->run() == FALSE){
			//$data["pesan_error"] .= trim(form_error('kd_biaya',' ',' '))==''?'':form_error('kd_biaya',' ',' ').'<br>';
			$data["pesan_error"] .= trim(validation_errors(' ',' '))==''?'':validation_errors(' ',' ');
		}else{
			$result = $this->mdl_pemasukan->InsertOnDb($data);
		}
		
		if($result){
			echo json_encode(array('success'=>true));
		}else{
			echo json_encode(array('msg'=>$data['pesan_error']));
		}
		
	}
}